# _*_ coding: utf-8 _*_
from odoo.addons.report_xlsx.report.report_xlsx import ReportXlsx


class PartnerXlsx(ReportXlsx):

    def generate_xlsx_report(self, workbook, data, productions):
        for production in productions:
            sheet = workbook.add_worksheet(u"入库清单")
            row = 0
            sheet.merge_range(row, 0, row, 14, u"入库清单", workbook.add_format({
                "font_size": 20,
                'align': 'center',
                'valign': 'vcenter',
            }))
            row += 1
            sheet.merge_range(row, 0, row, 14, u"单号：" + production.name)
            row += 1
            headers = [u"序号", u"机台号", u"班次", u"备注1", u"备注2", u"完工/批次", u"全长", u"内部参考", u"代码", u"追踪号", u"说明", u"辅助单位",
                       u"换算率", u"辅助单位数量", u"完成"]
            for index, header in enumerate(headers):
                sheet.write(row, index, header)
            row += 1

            lots = production.move_finished_ids.filtered(lambda m: m.state != "done").mapped("active_move_lot_ids")
            if lots:
                for index, lot in enumerate(lots, 1):
                    sheet.write(row, 0, index)
                    sheet.write(row, 1, lot.mrp_platform or "")
                    sheet.write(row, 2, lot.mrp_shift or "")
                    sheet.write(row, 3, lot.remark_one or "")
                    sheet.write(row, 4, lot.remark_two or "")
                    sheet.write(row, 5, lot.related_lot_id and lot.related_lot_id.name_get()[0][1] or "")
                    sheet.write(row, 6, lot.lot_lenth or "")
                    sheet.write(row, 7, lot.board_number or "")
                    sheet.write(row, 8, lot.code or "")
                    sheet.write(row, 9, lot.ref or "")
                    sheet.write(row, 10, lot.description or "")
                    sheet.write(row, 11, lot.lot_uom and lot.lot_uom.name_get()[0][1] or "")
                    sheet.write(row, 12, lot.lot_uom_ratio)
                    sheet.write(row, 13, lot.lot_uom_qty)
                    sheet.write(row, 14, lot.quantity_done)
                    row += 1

            sheet.set_row(0, 30)
            sheet.set_column(5, 5, 30)
            sheet.set_column(11, 11, 20)
            sheet.set_column(13, 13, 15)


PartnerXlsx('report.mrp.production.finished.moves.xlsx', 'mrp.production')
